﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Sector7.Framework.Core;
using Sector7.Framework.Enums;

namespace Sector7.Medical.Windows
{
    /// <summary>
    /// AuthenticationWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AuthenticationWindow : Window
    {
        #region Accessor
        /// <summary>
        /// 获取通过验证后的用户信息
        /// </summary>
        public string UserName
        {
            get { return txbUserName.Text; }
        }
        #endregion

        #region Public functions
        #endregion

        #region Private functions
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            string errorMsg = string.Empty;
            string userName = txbUserName.Text;
            string password = txbPassword.Password;

            if (string.IsNullOrWhiteSpace(userName))
            {
                errorMsg += "用户名不能为空！";
            }
            if (string.IsNullOrWhiteSpace(password))
            {
                if (errorMsg.Length > 0)
                {
                    errorMsg += "\n";
                }
                errorMsg += "密码不能为空！";
            }

            if (errorMsg.Length > 0)
            {
                Alert.ShowDialog(AlertType.Error, errorMsg);
            }
            else
            {
                this.DialogResult = true;
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
        #endregion

        #region Structure
        public AuthenticationWindow()
        {
            InitializeComponent();

            txbUserName.Focus();
        }
        #endregion

        #region Inner members
        #endregion
    }
}
